package sw.EngAdroid;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.util.DisplayMetrics;
import android.view.Window;

public class SinglePlayerActivity extends Activity {

	private TextView currentName;
	private TextView questionText;
	private TextView question;
	private EditText answerText;
	private ArrayList<String> playerNames;
	private Button submit;
	private boolean notdone;
	private int currentPlayer;
	private Game game;
	private int numberOfPlayers;
	private TextView myCounter;
	private sw.EngAdroid.CountDownTimer t;

	private Button bet0;
	private TextView guess0;
	private TextView ratio0;
	private EditText chips0;

	private Button bet1;
	private TextView guess1;
	private TextView ratio1;
	private EditText chips1;

	private Button bet2;
	private TextView guess2;
	private TextView ratio2;
	private EditText chips2;

	private Button bet3;
	private TextView guess3;
	private TextView ratio3;
	private EditText chips3;

	private Button bet4;
	private TextView guess4;
	private TextView ratio4;
	private EditText chips4;

	private Button bet5;
	private TextView guess5;
	private TextView ratio5;
	private EditText chips5;

	private TextView p0chips;
	private TextView p1chips;
	private TextView p2chips;
	private TextView p3chips;
	private TextView p4chips;
	private TextView p5chips;

	private TextView correctGuess;
	private Button nextRound;
	private Button endGame;
	private TextView playerNameBet;
	private boolean small = false;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);

		if(dm.widthPixels<1000){
			setContentView(R.layout.question_screen2);
			small = true;
		}
		else
			setContentView(R.layout.question_screen);
		startGame();
	}

	@Override
	protected void onStart() {
		super.onStart();
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	protected void onStop() {
		super.onStop();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	private void startGame() {
		currentPlayer = 0;
		notdone = true;
		Intent intentInfo = getIntent();
		Bundle info = intentInfo.getExtras();
		numberOfPlayers = info.getInt("comps");
		game = new Game("Test", numberOfPlayers + 1);
		String playerName = info.getString("userName");
		Player p = new Player(playerName);
		p.joinGame(game);
		for (int i = 0; i < numberOfPlayers; i++) {
			ComputerPlayer comp = new ComputerPlayer("Computer " + i + "");
			comp.joinGame(game);
		}
		placeGuess();
	}

	private void placeGuess() {
		if (small)
			setContentView(R.layout.question_screen2);
		else
			setContentView(R.layout.question_screen);
		
		currentName = (TextView) findViewById(R.id.playerName);
		questionText = (TextView) findViewById(R.id.questionText);
		answerText = (EditText) findViewById(R.id.answerTextBox);
		submit = (Button) findViewById(R.id.submitAnswerButton);
		currentName.setText(((Player) (game.getPlayers().get(currentPlayer)))
				.getPlayer_name());
		questionText.setText(game.getQuestion().getText());
		myCounter = (TextView) findViewById(R.id.timer);

		t = new sw.EngAdroid.CountDownTimer(30000, 1000) {
			@Override
			public void onTick(long millisUntilFinished) {
				myCounter.setText("Time Remaining: " + millisUntilFinished
						/ 1000);

			}

			@Override
			public void onFinish() {
				myCounter.setText("Times up!");
				answerText.setText("000000");
				getAnswer();
				submit.performClick();
			}
		}.start();

		getAnswer();

	}

	private void placeBets() {
		if (game.getPlayers().size() == 3) {
			if (small)
				setContentView(R.layout.playerboard3small);
			else
				setContentView(R.layout.playerboard3);
			
			bet0 = (Button) findViewById(R.id.confirm01);
			question = (TextView) findViewById(R.id.questionTextView1);
			guess0 = (TextView) findViewById(R.id.guess01);
			ratio0 = (TextView) findViewById(R.id.ratio01);
			chips0 = (EditText) findViewById(R.id.chips01);
			// bet1 = (Button)findViewById(R.id.confirm02);
			guess1 = (TextView) findViewById(R.id.guess02);
			ratio1 = (TextView) findViewById(R.id.ratio02);
			chips1 = (EditText) findViewById(R.id.chips02);
			// bet2 = (Button)findViewById(R.id.confirm03);
			guess2 = (TextView) findViewById(R.id.guess03);
			ratio2 = (TextView) findViewById(R.id.ratio03);
			chips2 = (EditText) findViewById(R.id.chips03);
			playerNameBet = (TextView) findViewById(R.id.gameNameView);
			playerNameBet.setText("Player name: "
					+ ((Player) game.getPlayers().get(currentPlayer))
							.getPlayer_name());

			List<Guess> guesses = game.getGuesses();
			question.setText(game.getQuestion().getText());
			ratio0.setText("Ratio: 2.0");
			ratio1.setText("Ratio: 2.0");
			ratio2.setText("Ratio: 2.0");
			guess0.setText("Guess: " + guesses.get(0).getGuess());
			guess1.setText("Guess: " + guesses.get(1).getGuess());
			guess2.setText("Guess: " + guesses.get(2).getGuess());

			myCounter = (TextView) findViewById(R.id.Timer);

			t = new sw.EngAdroid.CountDownTimer(30000, 1000) {
				@Override
				public void onTick(long millisUntilFinished) {
					myCounter.setText("Time Remaining: " + millisUntilFinished
							/ 1000);

				}

				@Override
				public void onFinish() {
					myCounter.setText("Times up!");
					bet0.performClick();
				}
			}.start();

			bet0.setOnClickListener(new Button.OnClickListener() {
				public void onClick(View v) {
					t.cancel();
					Player player = ((Player) game.getPlayers().get(currentPlayer));
					String one = chips0.getText().toString();
					if (!(one.equals("")))
						player.placeBet(0, Integer.parseInt(one));
					String two = chips1.getText().toString();
					if (!(two.equals("")))
						player.placeBet(1, Integer.parseInt(two));
					String three = chips2.getText().toString();
					if (!(three.equals("")))
						player.placeBet(2, Integer.parseInt(three));
					
					currentPlayer = 0;
					for(int i = 1; i<game.getPlayers().size(); i++){
						game.resetChipBets();
						ComputerPlayer comp = ((ComputerPlayer) (game.getPlayers().get(i)));
						comp.chooseBet(3);
					}
					winnings3();					
				}
			});
		}

		else if (game.getPlayers().size() == 4) {
			if (small)
				setContentView(R.layout.playerboard4small);
			else
				setContentView(R.layout.playerboard4);
			bet0 = (Button) findViewById(R.id.confirm01);
			question = (TextView) findViewById(R.id.questionTextView1);
			guess0 = (TextView) findViewById(R.id.guess01);
			ratio0 = (TextView) findViewById(R.id.ratio01);
			chips0 = (EditText) findViewById(R.id.chips01);

			// bet1 = (Button)findViewById(R.id.confirm02);
			guess1 = (TextView) findViewById(R.id.guess02);
			ratio1 = (TextView) findViewById(R.id.ratio02);
			chips1 = (EditText) findViewById(R.id.chips02);

			// bet2 = (Button)findViewById(R.id.confirm03);
			guess2 = (TextView) findViewById(R.id.guess03);
			ratio2 = (TextView) findViewById(R.id.ratio03);
			chips2 = (EditText) findViewById(R.id.chips03);

			guess3 = (TextView) findViewById(R.id.guess04);
			ratio3 = (TextView) findViewById(R.id.ratio04);
			chips3 = (EditText) findViewById(R.id.chips04);

			playerNameBet = (TextView) findViewById(R.id.gameNameView);
			playerNameBet.setText("Player name: "
					+ ((Player) game.getPlayers().get(currentPlayer))
							.getPlayer_name());

			List<Guess> guesses = game.getGuesses();
			question.setText(game.getQuestion().getText());
			ratio0.setText("Ratio: 2.0");
			ratio1.setText("Ratio: 2.0");
			ratio2.setText("Ratio: 2.0");
			ratio3.setText("Ratio: 2.0");

			guess0.setText("Guess: " + guesses.get(0).getGuess());
			guess1.setText("Guess: " + guesses.get(1).getGuess());
			guess2.setText("Guess: " + guesses.get(2).getGuess());
			guess3.setText("Guess: " + guesses.get(3).getGuess());

			myCounter = (TextView) findViewById(R.id.Timer);

			t = new sw.EngAdroid.CountDownTimer(30000, 1000) {
				@Override
				public void onTick(long millisUntilFinished) {
					myCounter.setText("Time Remaining: " + millisUntilFinished
							/ 1000);

				}

				@Override
				public void onFinish() {
					myCounter.setText("Times up!");
					bet0.performClick();
				}
			}.start();

			bet0.setOnClickListener(new Button.OnClickListener() {
				public void onClick(View v) {
					t.cancel();
					Player player = ((Player) game.getPlayers().get(
							currentPlayer));
					String one = chips0.getText().toString();
					if (!(one.equals("")))
						player.placeBet(0, Integer.parseInt(one));
					String two = chips1.getText().toString();
					if (!(two.equals("")))
						player.placeBet(1, Integer.parseInt(two));
					String three = chips2.getText().toString();
					if (!(three.equals("")))
						player.placeBet(2, Integer.parseInt(three));
					String four = chips3.getText().toString();
					if (!(four.equals("")))
						player.placeBet(3, Integer.parseInt(four));
					
					for(int i = 1; i<game.getPlayers().size(); i++){
						game.resetChipBets();
						ComputerPlayer comp = ((ComputerPlayer) (game.getPlayers().get(i)));
						comp.chooseBet(4);
					}
					winnings4();		
				}
			});
		}

		else if (game.getPlayers().size() == 5) {
			if (small)
				setContentView(R.layout.playerboard5small);
			else
				setContentView(R.layout.playerboard5);
			bet0 = (Button) findViewById(R.id.confirm01);
			question = (TextView) findViewById(R.id.questionTextView1);
			guess0 = (TextView) findViewById(R.id.guess01);
			ratio0 = (TextView) findViewById(R.id.ratio01);
			chips0 = (EditText) findViewById(R.id.chips01);

			// bet1 = (Button)findViewById(R.id.confirm02);
			guess1 = (TextView) findViewById(R.id.guess02);
			ratio1 = (TextView) findViewById(R.id.ratio02);
			chips1 = (EditText) findViewById(R.id.chips02);

			// bet2 = (Button)findViewById(R.id.confirm03);
			guess2 = (TextView) findViewById(R.id.guess03);
			ratio2 = (TextView) findViewById(R.id.ratio03);
			chips2 = (EditText) findViewById(R.id.chips03);

			guess3 = (TextView) findViewById(R.id.guess04);
			ratio3 = (TextView) findViewById(R.id.ratio04);
			chips3 = (EditText) findViewById(R.id.chips04);

			guess4 = (TextView) findViewById(R.id.guess05);
			ratio4 = (TextView) findViewById(R.id.ratio05);
			chips4 = (EditText) findViewById(R.id.chips05);

			playerNameBet = (TextView) findViewById(R.id.gameNameView);
			playerNameBet.setText("Player name: "
					+ ((Player) game.getPlayers().get(currentPlayer))
							.getPlayer_name());

			List<Guess> guesses = game.getGuesses();
			question.setText(game.getQuestion().getText());
			ratio0.setText("Ratio: 2.0");
			ratio1.setText("Ratio: 2.0");
			ratio2.setText("Ratio: 2.0");
			ratio3.setText("Ratio: 2.0");
			ratio4.setText("Ratio: 2.0");

			guess0.setText("Guess: " + guesses.get(0).getGuess());
			guess1.setText("Guess: " + guesses.get(1).getGuess());
			guess2.setText("Guess: " + guesses.get(2).getGuess());
			guess3.setText("Guess: " + guesses.get(3).getGuess());
			guess4.setText("Guess: " + guesses.get(4).getGuess());

			myCounter = (TextView) findViewById(R.id.Timer);

			t = new sw.EngAdroid.CountDownTimer(30000, 1000) {
				@Override
				public void onTick(long millisUntilFinished) {
					myCounter.setText("Time Remaining: " + millisUntilFinished
							/ 1000);

				}

				@Override
				public void onFinish() {
					myCounter.setText("Times up!");
					bet0.performClick();
				}
			}.start();

			bet0.setOnClickListener(new Button.OnClickListener() {
				public void onClick(View v) {
					t.cancel();
					Player player = ((Player) game.getPlayers().get(
							currentPlayer));
					String one = chips0.getText().toString();
					if (!(one.equals("")))
						player.placeBet(0, Integer.parseInt(one));
					String two = chips1.getText().toString();
					if (!(two.equals("")))
						player.placeBet(1, Integer.parseInt(two));
					String three = chips2.getText().toString();
					if (!(three.equals("")))
						player.placeBet(2, Integer.parseInt(three));
					String four = chips3.getText().toString();
					if (!(four.equals("")))
						player.placeBet(3, Integer.parseInt(four));
					String five = chips4.getText().toString();
					if (!(five.equals("")))
						player.placeBet(4, Integer.parseInt(five));

					for(int i = 1; i<game.getPlayers().size(); i++){
						game.resetChipBets();
						ComputerPlayer comp = ((ComputerPlayer) (game.getPlayers().get(i)));
						comp.chooseBet(5);
					}
					winnings5();		
				}
			});
		}

		else if (game.getPlayers().size() == 6) {
			if (small)
				setContentView(R.layout.playerboard6small);
			else
				setContentView(R.layout.playerboard6);
			bet0 = (Button) findViewById(R.id.confirm01);
			question = (TextView) findViewById(R.id.questionTextView1);
			guess0 = (TextView) findViewById(R.id.guess01);
			ratio0 = (TextView) findViewById(R.id.ratio01);
			chips0 = (EditText) findViewById(R.id.chips01);
			// bet1 = (Button)findViewById(R.id.confirm02);

			guess1 = (TextView) findViewById(R.id.guess02);
			ratio1 = (TextView) findViewById(R.id.ratio02);
			chips1 = (EditText) findViewById(R.id.chips02);
			// bet2 = (Button)findViewById(R.id.confirm03);

			guess2 = (TextView) findViewById(R.id.guess03);
			ratio2 = (TextView) findViewById(R.id.ratio03);
			chips2 = (EditText) findViewById(R.id.chips03);

			guess3 = (TextView) findViewById(R.id.guess04);
			ratio3 = (TextView) findViewById(R.id.ratio04);
			chips3 = (EditText) findViewById(R.id.chips04);

			guess4 = (TextView) findViewById(R.id.guess05);
			ratio4 = (TextView) findViewById(R.id.ratio05);
			chips4 = (EditText) findViewById(R.id.chips05);

			guess5 = (TextView) findViewById(R.id.guess06);
			ratio5 = (TextView) findViewById(R.id.ratio06);
			chips5 = (EditText) findViewById(R.id.chips06);

			playerNameBet = (TextView) findViewById(R.id.gameNameView);
			playerNameBet.setText("Player name: "
					+ ((Player) game.getPlayers().get(currentPlayer))
							.getPlayer_name());

			List<Guess> guesses = game.getGuesses();
			question.setText(game.getQuestion().getText());
			ratio0.setText("Ratio: 2.0");
			ratio1.setText("Ratio: 2.0");
			ratio2.setText("Ratio: 2.0");
			ratio3.setText("Ratio: 2.0");
			ratio4.setText("Ratio: 2.0");
			ratio5.setText("Ratio: 2.0");

			guess0.setText("Guess: " + guesses.get(0).getGuess());
			guess1.setText("Guess: " + guesses.get(1).getGuess());
			guess2.setText("Guess: " + guesses.get(2).getGuess());
			guess3.setText("Guess: " + guesses.get(3).getGuess());
			guess4.setText("Guess: " + guesses.get(4).getGuess());
			guess5.setText("Guess: " + guesses.get(5).getGuess());

			myCounter = (TextView) findViewById(R.id.Timer);

			t = new sw.EngAdroid.CountDownTimer(30000, 1000) {
				@Override
				public void onTick(long millisUntilFinished) {
					myCounter.setText("Time Remaining: " + millisUntilFinished
							/ 1000);

				}

				@Override
				public void onFinish() {
					myCounter.setText("Times up!");
					bet0.performClick();
				}
			}.start();

			bet0.setOnClickListener(new Button.OnClickListener() {
				public void onClick(View v) {
					t.cancel();
					Player player = ((Player) game.getPlayers().get(
							currentPlayer));
					String one = chips0.getText().toString();
					if (!(one.equals("")))
						player.placeBet(0, Integer.parseInt(one));
					String two = chips1.getText().toString();
					if (!(two.equals("")))
						player.placeBet(1, Integer.parseInt(two));
					String three = chips2.getText().toString();
					if (!(three.equals("")))
						player.placeBet(2, Integer.parseInt(three));
					String four = chips3.getText().toString();
					if (!(four.equals("")))
						player.placeBet(3, Integer.parseInt(four));
					String five = chips4.getText().toString();
					if (!(five.equals("")))
						player.placeBet(4, Integer.parseInt(five));
					String six = chips5.getText().toString();
					if (!(six.equals("")))
						player.placeBet(5, Integer.parseInt(six));

					for(int i = 1; i<game.getPlayers().size(); i++){
						game.resetChipBets();
						ComputerPlayer comp = ((ComputerPlayer) (game.getPlayers().get(i)));
						comp.chooseBet(6);
					}
					winnings6();		
				}
			});
		}
		// bet1.setOnClickListener(new Button.OnClickListener() {
		// public void onClick(View v){
		// Player player = ((Player)game.getPlayers().get(currentPlayer));
		// player.placeBet(1, Integer.parseInt(chips1.getText().toString()));
		// if(currentPlayer<(game.players.size()-1)){
		// currentPlayer++;
		// placeBets();
		// }
		// else{
		// currentPlayer=0;
		// winnings();
		// }
		// }
		// });
		// bet2.setOnClickListener(new Button.OnClickListener() {
		// public void onClick(View v){
		// Player player = ((Player)game.getPlayers().get(currentPlayer));
		// player.placeBet(2, Integer.parseInt(chips2.getText().toString()));
		// if(currentPlayer<(game.players.size()-1)){
		// currentPlayer++;
		// placeBets();
		// }
		// else{
		// currentPlayer=0;
		// winnings();
		// }
		// }
		// });
	}
	
	private void winnings3() {
		if (small)
			setContentView(R.layout.winnings3small);
		else
			setContentView(R.layout.winnings3);
		
		game.winnings();
		p0chips = (TextView) findViewById(R.id.player0);
		p1chips = (TextView) findViewById(R.id.player1);
		p2chips = (TextView) findViewById(R.id.player2);

		correctGuess = (TextView) findViewById(R.id.correctGuess);
		correctGuess.setText("Correct answer: "
				+ game.getQuestion().getAnswer());

		p0chips.setText(game.getPlayers().get(0).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(0).getChips());
		p1chips.setText(game.getPlayers().get(1).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(1).getChips());
		p2chips.setText(game.getPlayers().get(2).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(2).getChips());

		nextRound = (Button) findViewById(R.id.again);
		endGame = (Button) findViewById(R.id.endGame);
		game.displayAnswer();
		//game.clearBets();
		//game.clearGuesses();

		nextRound.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				//int temp = game.nextQuestion;
				//temp++;
				//game.nextQuestion = temp;
				placeGuess();
			}
		});

		endGame.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});

	}
	
	private void winnings4() {
		if (small)
			setContentView(R.layout.winnings4small);
		else
			setContentView(R.layout.winnings4);
		
		game.winnings();
		p0chips = (TextView) findViewById(R.id.player0);
		p1chips = (TextView) findViewById(R.id.player1);
		p2chips = (TextView) findViewById(R.id.player2);
		p3chips = (TextView) findViewById(R.id.player3);

		correctGuess = (TextView) findViewById(R.id.correctGuess);
		correctGuess.setText("Correct answer: "
				+ game.getQuestion().getAnswer());

		p0chips.setText(game.getPlayers().get(0).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(0).getChips());
		p1chips.setText(game.getPlayers().get(1).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(1).getChips());
		p2chips.setText(game.getPlayers().get(2).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(2).getChips());
		p3chips.setText(game.getPlayers().get(3).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(3).getChips());

		nextRound = (Button) findViewById(R.id.again);
		endGame = (Button) findViewById(R.id.endGame);
		game.displayAnswer();
		//game.clearBets();
		//game.clearGuesses();

		nextRound.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				//int temp = game.nextQuestion;
				//temp++;
				//game.nextQuestion = temp;
				placeGuess();
			}
		});

		endGame.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});

	}

	private void winnings5() {
		if (small)
			setContentView(R.layout.winnings5small);
		else
			setContentView(R.layout.winnings5);
		
		game.winnings();
		p0chips = (TextView) findViewById(R.id.player0);
		p1chips = (TextView) findViewById(R.id.player1);
		p2chips = (TextView) findViewById(R.id.player2);
		p3chips = (TextView) findViewById(R.id.player3);
		p4chips = (TextView) findViewById(R.id.player4);

		correctGuess = (TextView) findViewById(R.id.correctGuess);
		correctGuess.setText("Correct answer: "
				+ game.getQuestion().getAnswer());

		p0chips.setText(game.getPlayers().get(0).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(0).getChips());
		p1chips.setText(game.getPlayers().get(1).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(1).getChips());
		p2chips.setText(game.getPlayers().get(2).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(2).getChips());
		p3chips.setText(game.getPlayers().get(3).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(3).getChips());
		p4chips.setText(game.getPlayers().get(4).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(4).getChips());

		nextRound = (Button) findViewById(R.id.again);
		endGame = (Button) findViewById(R.id.endGame);
		game.displayAnswer();
		//game.clearBets();
		//game.clearGuesses();

		nextRound.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				//int temp = game.nextQuestion;
				//temp++;
				//game.nextQuestion = temp;
				placeGuess();
			}
		});

		endGame.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});

	}
	
	private void winnings6() {
		if (small)
			setContentView(R.layout.winnings6small);
		else
			setContentView(R.layout.winnings6);
		
		game.winnings();
		p0chips = (TextView) findViewById(R.id.player0);
		p1chips = (TextView) findViewById(R.id.player1);
		p2chips = (TextView) findViewById(R.id.player2);
		p3chips = (TextView) findViewById(R.id.player3);
		p4chips = (TextView) findViewById(R.id.player4);
		p5chips = (TextView) findViewById(R.id.player5);

		correctGuess = (TextView) findViewById(R.id.correctGuess);
		correctGuess.setText("Correct answer: "
				+ game.getQuestion().getAnswer());

		p0chips.setText(game.getPlayers().get(0).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(0).getChips());
		p1chips.setText(game.getPlayers().get(1).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(1).getChips());
		p2chips.setText(game.getPlayers().get(2).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(2).getChips());
		p3chips.setText(game.getPlayers().get(3).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(3).getChips());
		p4chips.setText(game.getPlayers().get(4).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(4).getChips());
		p5chips.setText(game.getPlayers().get(5).getPlayer_name() + "'s chips: "
				+ game.getPlayers().get(5).getChips());

		nextRound = (Button) findViewById(R.id.again);
		endGame = (Button) findViewById(R.id.endGame);
		game.displayAnswer();
		//game.clearBets();
		//game.clearGuesses();

		nextRound.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				//int temp = game.nextQuestion;
				//temp++;
				//game.nextQuestion = temp;
				placeGuess();
			}
		});

		endGame.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});

	}

	private void getAnswer() {
		submit.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				Player player = ((Player) game.getPlayers().get(currentPlayer));
				int numGuess = Integer
						.parseInt(answerText.getText().toString());
				// Guess guess = new Guess(player.getPlayer_name(), numGuess);
				player.submitGuess(numGuess);
				t.cancel();
				for (int i = 1; i < game.getPlayers().size(); i++) {
					ComputerPlayer comp = ((ComputerPlayer) (game.getPlayers()
							.get(i)));
					comp.submitGuess(game.getQuestion().getAnswer());
				}
				placeBets();
			}
		});
	}
}
